package com.design.pattern.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class BigCarFlyWeightFactory {
    private static Map<Integer,CarFlyWeight> cars=new ConcurrentHashMap();

    public static CarFlyWeight get(Integer wheels ){
        CarFlyWeight car=cars.get(wheels);
        if (null==car){
            car=new BigCarConcreteFlyWeight();
            ((BigCarConcreteFlyWeight)car).setWheels(wheels);
            cars.put(wheels,car);
        }
        return car;
    }
    public static void add(BigCarConcreteFlyWeight carFlyWeight){
        CarFlyWeight car=cars.get(carFlyWeight.getWheels());
        if (null==car){
            cars.put(carFlyWeight.getWheels(),carFlyWeight);
        }
    }
    public static void delete(BigCarConcreteFlyWeight carFlyWeight){
        CarFlyWeight car=cars.get(carFlyWeight.getWheels());
        if (null!=car){
            cars.remove(carFlyWeight.getWheels(),carFlyWeight);
        }
    }
}
